#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
prefix="[ **** ] /etc/rc.local:"
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "$prefix My IP address is %s\n" "$_IP"
fi

model=$(tr -d '\0' < /proc/device-tree/model)
compatible=$(tr -d '\0' < /proc/device-tree/compatible)
printf "model: $model\n"
printf "compatible: $compatible\n"

# xenomai initialization
if grep BCM2708 /proc/cpuinfo >/dev/null
then 
  echo "$prefix use /usr/xenomai_pi1_cobalt as /usr/xenomai"
  ln -nsf /usr/xenomai_pi1_cobalt /usr/xenomai  
else 
  echo "$prefix use /usr/xenomai_pi2_cobalt as /usr/xenomai"  
  ln -nsf /usr/xenomai_pi2_cobalt /usr/xenomai  
fi

# for xenomai 3.0.5
#modprobe xeno_gpio  || true
# for xenomai 3.0.8
modprobe xeno-gpio-bcm2835 || true

# by default turn clock leds off (clock exercise)
# leds are connected to gpio pins 2 3 4 17 27 22 10 9
echo "$prefix set output value 0 on gpio pins  2 3 4 17  27 22 10 9"
for d in 2 3 4 17 27 22 10 9
do 
  gpio -g mode $d out
  gpio -g write $d 0
done


sleep 5
/usr/local/bin/update_ip_at_dyndns_server
     


exit 0

